﻿@model Inovout.Kuajing.Models.Warehouse
@{
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}
@section styles {

    <style>
        .form form {
            margin: 20em auto;
        }

        div.error {
            padding-left: 2px;
            padding-bottom: 2px;
            font-weight: bold;
            color: #EA5200;
        }

        #warehouseForm select {
            max-width: 280px;
        }
    </style>
}

@section scriptsHead {
    <script>

        var page = {};
        page.initCity = function (locationId) {
            $.ajax({
                url: '@Url.Action("GetAllCities", "Location")',
                type: "GET",
                dataType: "json",
                data: { locaionId: locationId },
                success: function (data) {
                    $("#LocationCity").empty();
                    $("#LocationRegion").empty();
                    $.each(data, function (index, item) {
                        var option = "<option value=" + item.LocationCity + ">" + item.LocationCityName + "</option>";
                        $("#LocationCity").append($(option));
                    })

                    page.initRegion($("#LocationCity option:selected").val());
                },
                error: function (jqXHR, textStatus, errorThrown) {


                }
            })

        }

        page.initRegion = function (locationId) {
            $.ajax({
                url: '@Url.Action("GetAllRegions", "Location")',
                type: "GET",
                dataType: "json",
                data: { locaionId: locationId },
                success: function (data) {
                    $("#LocationRegion").empty();
                    $.each(data, function (index, item) {
                        var option = "<option value=" + item.LocationRegion + ">" + item.LocationRegionName + "</option>";
                        $("#LocationRegion").append($(option));
                    })
                },
                error: function (jqXHR, textStatus, errorThrown) {


                }
            })

        }



        $(document).ready(function () {

            $.ajax({
                url: '@Url.Action("GetAllProvices", "Location")',
                type: "Get",
                dataType: "json",
                success: function (data) {
                    $.each(data, function (index, item) {
                        var option = "<option value=" + item.LocationProvince + ">" + item.LocationProvinceName + "</option>";
                        $("#LocationProvince").append($(option));
                    })
                    $("#LocationProvince").val("320000");
                }
            })


            $.ajax({
                url: '@Url.Action("GetAllCities", "Location")',
                type: "Get",
                dataType: "json",
                data: { locaionId: "320000" },
                success: function (data) {
                    $.each(data, function (index, item) {
                        if (index == 0) {
                            var option = "<option value=" + item.LocationCity + " selected=\"selected\">" + item.LocationCityName + "</option>";
                            $("#LocationCity").append($(option));
                        } else {
                            var option = "<option value=" + item.LocationCity + ">" + item.LocationCityName + "</option>";
                            $("#LocationCity").append($(option));
                        }

                    })
                }
            })




            $.ajax({
                url: '@Url.Action("GetAllRegions", "Location")',
                type: "Get",
                dataType: "json",
                data: { locaionId: "320100" },
                success: function (data) {
                    $.each(data, function (index, item) {
                        if (index == 0) {
                            var option = "<option value=" + item.LocationRegion + " selected=\"selected\">" + item.LocationRegionName + "</option>";
                            $("#LocationRegion").append($(option));
                        } else {
                            var option = "<option value=" + item.LocationRegion + ">" + item.LocationRegionName + "</option>";
                            $("#LocationRegion").append($(option));
                        }

                    })
                },
                error: function (jqXHR, textStatus, errorThrown) {

                }
            })

            $("#LocationProvince").on("change", function () {
                $("#LocationCity").empty();
                var value = $("#LocationProvince option:selected").val();
                page.initCity(value);

            })

            $("#LocationCity").on("change", function () {
                $("#LocationRegion").empty();
                var value = $("#LocationCity option:selected").val();
                page.initRegion(value);
            })


            $("#warehouseForm").validate({
                rules: {
                    Name: {
                        required: true,
                        minlength: 3
                    }
                },
                messages: {
                    Name: {
                        required: "请输入仓库名称",
                        minlength: "最小长度不小于3"
                    }
                },
                errorElement: "div"
            })
        })

    </script>

}

<div>
    @using (Html.BeginForm("Create", "Warehouse", FormMethod.Post, new { @class = "form-horizontal ", @id = "warehouseForm" }))
    {
        @Html.ValidationSummary(true)
        <div class="form-group">
            @Html.LabelFor(model => model.Name, "名称", new { @for = "CommpanyName", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(mode => mode.Name, new { @placeholder = "南京三宝", @class = "form-control" })
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.LocationProvince, "省", new { @for = "LocationProvince", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                <select name="LocationProvince" class="form-control" id="LocationProvince"></select>

            </div>

        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.LocationCity, "市", new { @for = "LocationCity", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                <select name="LocationCity" class="form-control" id="LocationCity"></select>
            </div>

        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.LocationRegion, "区", new { @for = "LocationRegion", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                <select name="LocationRegion" class="form-control" id="LocationRegion"></select>
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.HourseCategory, "类型", new { @for = "HourseCategory", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                <select name="HourseCategory" class="form-control" id="HourseCategory">
                    <option value="0" selected="selected">跨境保税仓</option>
                    <option value="1">跨境完税仓</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.ShippingTemplate, "运费模板", new { @for = "ShippingTemplate", @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @*  @Html.DropDownListFor(model => model.LocationProvince, null, new { @class = "form-control" })*@
                @Html.DropDownListFor(model => model.ShippingTemplate.Id, (SelectList)ViewData["ShippingTemplate"], new { @class = "form-control" })
            </div>
        </div>
        <div class="form-group">
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="submit" id="export" class="btn btn-default" value="申请" />
            </div>
        </div>
    }

</div>

